package bs

import scala.xml.NodeSeq

trait LiftComponent {
  val template: NodeSeq
  val decorators = collection.mutable.Buffer.empty[NodeSeq => NodeSeq]

  def transformer: NodeSeq => NodeSeq = identity

  def decorateWith(decorator: NodeSeq=>NodeSeq):this.type = {
    decorators += decorator
    this
  }

  def render = {
    val node = transformer.apply(template)
    val result = if (decorators.isEmpty)
        node
      else
        decorators.reduce(_ andThen _).apply(node)
//    val result = (before.reduce(_ andThen _) andThen transformer andThen after.reduce(_ andThen _)).apply(template)
//    println(result)
    result
  }
}
